<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html>
<jsp:include page="../common/import.jsp" flush="true"></jsp:include>
<body>

<jsp:include page="../common/header.jsp" flush="true"></jsp:include>

<div class="main p20">
	<div class="container clear">
        <ul class="left-nav fl pt20 w200">
        <c:if test="${sales.parentId=='0'}">
            <li><a href="${base}/agent/agent/agentList.xhtml"><span class="iconfont">&#xf014b;</span>代理商</a></li>
        </c:if>
        <c:if test="${sales.parentId=='1'}">
        	<li><a href="${base}/agent/agent/agentList.xhtml"><span class="iconfont">&#xf014b;</span>代理商</a></li>
        </c:if>
            <li><a class="ahover" href="${base}/agent/sales/salesList.xhtml"><span class="iconfont">&#xf014d;</span>业务员</a></li>
        </ul>
        <li><a href="${base}/agent/merchant/merchantList.xhtml"><span class="iconfont">&#xf014d;</span>商户</a></li>
        <div class="main-right fr">
        	<div class="b m20 b-radius">
            	<div class="clear bgf5 bb">
                	<h2 class="fl h30 lg30 p5 pl10">编辑业务员</h2>
                    <a href="javascript:" class="fr h20 p5 m5 w50 bg1eb9ef cfff b-radius tc" onclick="back()">返回</a>
                </div>
                
                <div class="p10 mt20">
                	<p class="bb c1eb9ef">基本信息&#10043;为必填项</p>
                    <input id="salesId" value="${sales.id}" hidden="true">
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5"><span class="ce60012">&#10043;</span>姓名：</span>
                        <input id="name" class="fl w400 h20 p5 b-radius" type="text" value="${sales.name}">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5"><span class="ce60012">&#10043;</span>手机号：</span>
                        <input id="phone" class="fl w400 h20 p5 b-radius" type="text" value="${sales.phone}">
                        <span class="fl w200 tl f12 h20 lg20 p5 ce60012">&#10043;手机号码为作业app的登录账号</span>
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5">职位：</span>
                        <input id="job" class="fl w400 h20 p5 b-radius" type="text" value="${sales.job}">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5">工号：</span>
                        <input id="jobNum" class="fl w400 h20 p5 b-radius" type="text" value="${sales.jobNum}" readonly="readonly">
                    </div>

                    <div class="tc p50">
                    	<button class="w100 bga0 h20 p10 b-radius" onclick="back()">取消</button>
                        <button class="w100 bgac1 cfff h20 p10 ml30 b-radius" onclick="submit()">保存</button>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
</div>

<jsp:include page="../common/footer.jsp" flush="true"></jsp:include>

<script type="text/javascript">
function back(){
	window.location.href="${base}/agent/sales/salesList.xhtml";
}
//数据提交
function submit(){
	var salesId = document.getElementById("salesId").value;
	var name=document.getElementById("name").value;
	var phone = document.getElementById("phone").value;
	var job = document.getElementById("job").value;

	if (name==''||name==null) {
		alert("姓名不能为空");
		return false;
	}
	var mobile= phone;
	if(mobile.length==0)
    {
       alert('请输入手机号码！');
       //document.form1.mobile.focus();
       return ;
    }    
    if(mobile.length!=11)
    {
        alert('请输入11位有效的手机号码！');
       // document.form1.mobile.focus();
        return ;
    }
    
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test(mobile))
    {
        alert('请输入有效的手机号码！');
        //document.form1.mobile.focus();
        return ;
    }
    
	var url= "${pageContext.request.contextPath}/sales/edit.xhtml";
	var data = {"salesId":salesId,"name":name,"phone":phone,"job":job};
	
	$.ajax({
        url: url,
        type: "POST",
        data: data,
        dataType: "json",
        success: function (data) {
        	if (data.status=='1') {
				alert(data.info);
				window.location.href="${base}/agent/sales/salesList.xhtml";
		        //location.reload(true);
			}
        	if(data.status=='0'){
				alert(data.info);
			}
        },
        error: function (data) {
            alert('服务端报错，' + data.status);
        }
    });
	
}
//手机校验
function validatemobile(mobile)
{
    if(mobile.length==0)
    {
       alert('请输入手机号码！');
       //document.form1.mobile.focus();
       return false;
    }    
    if(mobile.length!=11)
    {
        alert('请输入11位有效的手机号码！');
       // document.form1.mobile.focus();
        return false;
    }
    
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test(mobile))
    {
        alert('请输入有效的手机号码！');
        //document.form1.mobile.focus();
        return false;
    }
}


</script>
</body>
</html>